var app = getApp();

Page({
  data: {
    titel: ["全部", "待付款", "待确认", '待入住', '已完成', '已取消'],
    page: 1,
    order_list: []
  },
  onLoad: function(e) {
    wx.setNavigationBarColor({
      frontColor: '#000000',
          backgroundColor: '#ffffff'
    }), app.getUserInfo(function(e) {
      console.log(e);
    });
    var t = e.activeIndex,
      a = e.index;
    console.log(a), this.setData({
      activeIndex: t,
      index: a,
      url: wx.getStorageSync("url"),
      color: wx.getStorageSync("platform").color
    }), this.refresh();
  },
  refresh: function(e) {
    var o = this,
      i = o.data.page,
      n = o.data.order_list,
      s = o.data.index;
    console.log(s);
    var t = wx.getStorageSync("userInfo").id,
      a = app.today_time();
    console.log('用户id' + t);
    app.util.request({
      url: "entry/wxapp/MyOrder",
      cachetime: "0",
      data: {
        user_id: t,
        // user_id: 182,
        page: i
      },
      success: function(e) {
        console.log(e.data.length);
        if (0 < e.data.length) {
          o.setData({
            page: i + 1
          }), n = n.concat(e.data);
          var t = [],
            a = [],
            d = [],
            w = [],
            q = [];
          for (var r in n) n[r].arrival_time = n[r].arrival_time.slice(5, 7) + "月" + n[r].arrival_time.slice(8, 10) + "日",
          n[r].departure_time = n[r].departure_time.slice(5, 7) + "月" + n[r].departure_time.slice(8, 10) + "日",
          1 == n[r].status && t.push(n[r]),
          2 == n[r].status && a.push(n[r]),
          2.5 == n[r].status && d.push(n[r]),
          4 == n[r].status && w.push(n[r]),
          5 == n[r].status && w.push(n[r]),
          3 == n[r].status && q.push(n[r]),
          console.log(n[r].status);
          console.log(n);
          console.log(t);
          console.log(a);
          console.log(d);
          console.log(w);
          console.log(q);
          0 == s ? o.setData({
            order_list: n
          }) : 1 == s ? o.setData({
            order_list: t
          }) : 2 == s ? o.setData({
            order_list: a
          }) : 3 == s ? o.setData({
            order_list: d
          }) : 4 == s ? o.setData({
            order_list: w
          }) : 5 == s && o.setData({
            order_list: q
          });
        }
      }
    });
  },
  tabClick1: function(e) {
    console.log(e.currentTarget.dataset.index);
    var o = this;
    o.setData({
      activeIndex: e.currentTarget.dataset.index
    })
  },
  tabClick: function(e) {
    console.log(e), this.setData({
      activeIndex: e.currentTarget.dataset.index,
      index: e.currentTarget.dataset.index,
      page: 1,
      order_list: []
    }), this.refresh();
  },
  order_info: function(e) {
    var t = e.currentTarget.dataset.id;
    console.log(t);
    wx.navigateTo({
      url: "orderinfo?id=" + t
    });
  },
  onReady: function() {},
  onShow: function() {
    this.setData({
      index: 0,
      activeIndex: 0,
      page: 1,
      order_list: []
    }), this.refresh();
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {
    console.log(this.data.page), this.setData({
      page: 1,
      order_list: []
    }), this.refresh(), wx.stopPullDownRefresh();
  },
  onReachBottom: function() {
    this.refresh();
  },
  onShareAppMessage: function() {}
});